package cn.cpy.sms.login.controller;

import cn.cpy.sms.login.common.web.JsonResult;
import cn.cpy.sms.login.pojo.param.UserLoginParam;
import cn.cpy.sms.login.service.IPassportService;
import cn.cpy.sms.login.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@RestController
@RequestMapping("/v1/passport")
public class PassportController {
    @Autowired
    SmsUtil smsUtil;
    @Autowired
    IPassportService passportService;
    //存储需要验证的手机号和验证码
//    Map<String, String> phoneCodeMap=new ConcurrentHashMap<String,String>();

    @GetMapping("postSmsCode")
    public JsonResult postSmsCode(String phone){
        passportService.postSmsCode(phone);
        //用来保存手机号和验证码
//        phoneCodeMap.put(phone);
        return JsonResult.ok();
    }

    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.info("处理登录:"+userLoginParam);
        passportService.handleLogin(userLoginParam);
        return JsonResult.ok();
    }

    @GetMapping("logout")
    public void logout(String phone){
        passportService.logout(phone);
    }
}
